package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.GetUserByUsernameAndPwdBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetUserByUsernameAndPwdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
/**
*根据用户名密码查询用户信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserByUsernameAndPwd{
	private static GetUserByUsernameAndPwdBean getuserbyusernameandpwdBean;
	private static GetUserByUsernameAndPwdCall getuserbyusernameandpwdCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户名密码查询用户信息");
	}

	@Before
	public void caseUp() {
		getuserbyusernameandpwdBean=new GetUserByUsernameAndPwdBean();
		getuserbyusernameandpwdCall=new GetUserByUsernameAndPwdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserbyusernameandpwdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserByUsernameAndPwd_001() {
		Logger.start(true,"根据用户名密码查询用户信息成功");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserbyusernameandpwdBean.setUsername(u.getLoginId());
			getuserbyusernameandpwdBean.setPassword(u.getLoginPwd());
			getuserbyusernameandpwdCall.setData(getuserbyusernameandpwdBean);
			getuserbyusernameandpwdCall.callService();			
			Logger.verifyEquals("true", getuserbyusernameandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(user, getuserbyusernameandpwdCall.getJsonObject().get("userDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserByUsernameAndPwd_002() {
		Logger.start(true,"密码不匹配没有查到数据");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserbyusernameandpwdBean.setUsername(u.getLoginId());
			getuserbyusernameandpwdBean.setPassword(u.getLoginPwd()+1);
			getuserbyusernameandpwdCall.setData(getuserbyusernameandpwdBean);
			getuserbyusernameandpwdCall.callService();			
			Logger.verifyEquals("true", getuserbyusernameandpwdCall.getString("success"), "验证success");
			Logger.verifyIsNull(getuserbyusernameandpwdCall.getJsonObject().get("userDto"), "验证没有返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserByUsernameAndPwd_003() {
		Logger.start(true,"不输用户名失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
//			getuserbyusernameandpwdBean.setUsername(u.getLoginId());
			getuserbyusernameandpwdBean.setPassword(u.getLoginPwd());
			getuserbyusernameandpwdCall.setData(getuserbyusernameandpwdBean);
			getuserbyusernameandpwdCall.callService();			
			Logger.verifyEquals("false", getuserbyusernameandpwdCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserByUsernameAndPwd_004() {
		Logger.start(true,"不输入密码失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserbyusernameandpwdBean.setUsername(u.getLoginId());
//			getuserbyusernameandpwdBean.setPassword(u.getLoginPwd());
			getuserbyusernameandpwdCall.setData(getuserbyusernameandpwdBean);
			getuserbyusernameandpwdCall.callService();			
			Logger.verifyEquals("false", getuserbyusernameandpwdCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}